﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace QLKS
{
    public partial class fmrTraCuuPhong : DevExpress.XtraEditors.XtraForm
    {
        public fmrTraCuuPhong()
        {
            InitializeComponent();
        }

        private void fmrTraCuuPhong_Load(object sender, EventArgs e)
        {
            lkePhong.Properties.DataSource = BUS.PhongBUS.SelectCobobox(0).Tables[0];
            lkePhong.Properties.DisplayMember = "TenPhong";
            lkePhong.Properties.ValueMember = "MaPhong";
            lkeLoaiPhong.Properties.DataSource = BUS.LoaiPhongBUS.SelectCobobox().Tables[0];
            lkeLoaiPhong.Properties.DisplayMember = "TenLoaiPhong";
            lkeLoaiPhong.Properties.ValueMember = "MaLoaiPhong";
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            DTO.PhongDTO phong = new DTO.PhongDTO() { MaPhong = Convert.ToInt32(lkePhong.EditValue), MaLoaiPhong = Convert.ToInt32(lkeLoaiPhong.EditValue), TinhTrangPhong = chkTinhTrang.Checked ? 0 : 1 };
            gridControl1.DataSource=BUS.PhongBUS.Search(phong, Convert.ToInt32(spinDonGiaTren.EditValue), Convert.ToInt32(spinDonGiaDuoi.EditValue)).Tables[0];
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void lkePhong_ProcessNewValue(object sender, DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs e)
        {
            if (String.IsNullOrEmpty(lkePhong.Text))
            {
                lkePhong.EditValue = null;                
            }
        }

        private void lkeLoaiPhong_Properties_EditValueChanged(object sender, EventArgs e)
        {
            lkePhong.Properties.DataSource = BUS.PhongBUS.SelectCobobox(Convert.ToInt32(lkeLoaiPhong.EditValue)).Tables[0];
        }
    }
}